package com.pingancar.creditmanage.dao;

import com.pingancar.creditmanage.pojo.UserPojo;
import com.pingancar.creditmanage.util.myenum.UserField;
import org.springframework.stereotype.Repository;

import java.util.List;
/**
 *Created by system on Tue Sep 09 11:17:13 CST 2014
 */
@Repository
public class UserDaoImpl extends BaseDAO<UserPojo> {

    public UserPojo increaseCredit(Integer id,  Integer credit) {

        UserPojo user = load(id);

        if (user == null)
            return null;

        Integer curr = user.getCredit();
        user.setCredit(curr + credit);
        update(user);

        return user;
    }

    public UserPojo decreaseCredit(Integer id, Integer credit) {

        UserPojo user = load(id);

        if (user == null)
            return null;

        Integer curr = user.getCredit();

        if (curr < credit)
            return null;

        user.setCredit(curr - credit);
        update(user);

        return user;
    }
}